home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 April / macformat-075.iso / Shareware Plus / Applications / Alpha / Tcl / Completions / TeXCompletions.tcl < prev   
Encoding:
Text File  |  1999-01-15  |  17.2 KB  |  548 lines  |  [TEXT/ALFA]

  1. ## -*-Tcl-*-
  2.  # ###################################################################
  3.  #    Vince's    Additions -    an extension package for Alpha
  4.  # 
  5.  #    FILE: "TeXCompletions.tcl"
  6.  #                      created: 26/2/96 {2:27:17 pm} 
  7.  #                      last update: 15/1/1999 {6:51:40 pm} 
  8.  #    Author:    Vince Darley
  9.  #    E-mail:    <darley@fas.harvard.edu>
  10.  #      mail:    Division of    Applied    Sciences, Harvard University
  11.  #            Oxford Street, Cambridge MA    02138, USA
  12.  #       www:    <http://www.fas.harvard.edu/~darley/>
  13.  #    
  14.  #    Adds completion routines for TeX mode.  This includes reference
  15.  #    (\label) completion, citation completion, environment completion,
  16.  #    environment item insertion.  
  17.  #    
  18.  #    Cool new feature: the '{' key is bound to electric completion.
  19.  #    This means you can just type as normal in most circumstances,
  20.  #    and when you hit '{', if the previous text is capable of being
  21.  #    extended as a command (e.g. \begin, \frac, ...), then it is!
  22.  # 
  23.  #  modified by  rev reason
  24.  #  -------- --- --- -----------
  25.  #  18/12/97 VMD 1.1 added TeX::IncludeFile completions, better handling of '*'
  26.  #  14/1/98  VMD 1.2 Env completion rewritten, some in core latex mode
  27.  #  28/1/98  VMD 1.3 huge thanks to Pierre Basso for improvements.
  28.  # ###################################################################
  29.  ##
  30.  
  31. # ◊◊◊◊ completions & expanders ◊◊◊◊ #
  32. ensureset completions(TeX) {beginContraction Env Cmd Electric Reference Cite Word}
  33. ensureset expanders(TeX) {ExCmd}
  34.  
  35. # ◊◊◊◊ Preferences ◊◊◊◊ #
  36.  
  37. # Add an item inside any environment 
  38. # bound to shift-opt-i
  39. newPref binding TeXAddItem "/I<U<I" TeX "" 1
  40.  
  41. newPref f showTitlesWithTeXCiteCompletion 1 TeX
  42. # complete an environment even if we don't recognise it!
  43. newPref f acceptAnyTeXEnvironment 1 TeX
  44. # if we don't recognise the environment, create a body on the fly
  45. newPref f promptToCreateTeXEnvironment 1 TeX
  46. newPref f electricContractions 1 TeX
  47.  
  48. # ◊◊◊◊ extra invoker key ◊◊◊◊ #
  49.  
  50. proc TeX::electricLeft {} {
  51.     global TeXmodeVars
  52.     set p [getPos]
  53.     if {$TeXmodeVars(electricContractions)} {
  54.     catch {TeX::Completion::beginContraction}
  55.     }
  56.     if {[pos::compare [getPos] == $p]} {
  57.     catch {TeX::Completion::Electric}
  58.     }
  59.     if {[pos::compare [getPos] == $p]} {
  60.     insertText "\{"
  61.     }
  62. }
  63.  
  64. proc TeX::electricRight {} {
  65.     insertText "\}"
  66.     catch {blink [matchIt "\}" [pos::math [getPos] - 2]]}
  67. }
  68.  
  69. # ◊◊◊◊ Completions ◊◊◊◊ #
  70.  
  71. ## 
  72.  # -------------------------------------------------------------------------
  73.  # 
  74.  # "TeX::Completion::beginContraction" --
  75.  # 
  76.  #  The idea here is to see if you see a hint in the form of 
  77.  #  "b'<some-word>", if so replace the "b'" with "\begin ".
  78.  # -------------------------------------------------------------------------
  79.  ##
  80. proc TeX::Completion::beginContraction {{dummy ""}} {
  81.     set lastword [completion::lastTwoWords leadingHint]
  82.     if {$leadingHint != "b'"} {return 0} 
  83.     set curPos [getPos]
  84.     backwardWord
  85.     set startEnvPos [getPos]
  86.     set evironmentHint [getText $startEnvPos $curPos]
  87.     backwardWord
  88.     deleteText [getPos] $curPos
  89.     insertText "\\begin"
  90.     TeX::Completion::Electric "begin"
  91.     typeText $lastword
  92.     return 0
  93. }
  94.  
  95. ## 
  96.  # -------------------------------------------------------------------------
  97.  #     
  98.  # "TeX::Completion::Env" --
  99.  #    
  100.  #    Complete the contents of a \begin...\end pair as appropriate.  Uses    the
  101.  #    TeXbodies array.  You can either type '\begin<cmd-Tab>figure<cmd-Tab>'
  102.  #    (for example) or just '\begin{figure}<cmd-Tab>'.
  103.  # -------------------------------------------------------------------------
  104.  ##
  105. proc TeX::Completion::Env {dummy} {
  106.     set cmd [completion::lastTwoWords begin]
  107.     if { $begin != "\\begin\{" } { return 0 }
  108.     if [regexp {^(.*)\}$} $cmd "" cmd] {
  109.     # hmm
  110.     }
  111.     set matches [completion::fromList $cmd TeXenvironments]
  112.     if { $matches == "" } {
  113.     global TeXmodeVars TeXbodies
  114.     if [info exists TeXbodies($cmd)] {
  115.         set match $cmd
  116.     } else {            
  117.         if {$TeXmodeVars(acceptAnyTeXEnvironment)} {
  118.         if $TeXmodeVars(promptToCreateTeXEnvironment) {
  119.             set y 40
  120.             set yb 200
  121.             set res [eval dialog -w 400 -h 340 \
  122.               [dialog::title "New TeX environment" 400] \
  123.               [dialog::button "OK" 310 yb] \
  124.               [dialog::button "Cancel" 310 yb] \
  125.               [dialog::text "Enter the template for the body of the environment" 10 y] \
  126.               [dialog::text "Write '•prompt message•' for each template stop," 10 y] \
  127.               [dialog::text "'\\r','\\\{','\\t',... for return, brace, tab etc." 10 y] \
  128.               [dialog::edit "•body•" 10 y 35 6] \
  129.               ]
  130.             set match $cmd
  131.             if {![lindex $res 1]} {
  132.             eval set "TeXbodies($match)" [lindex $res 2]
  133.             addUserLine "set TeXbodies($match) \"[quoteExpr3 $TeXbodies($match)]\""
  134.             } else {
  135.             # we cancelled, so move on
  136.             completion::already error
  137.             return 1
  138.             }
  139.         } else {
  140.             message "Warning: I don't recognise that environment"
  141.             set match $cmd
  142.         }
  143.         } else {
  144.         return 0
  145.         }
  146.     }
  147.     } else {
  148.     set match [completion::Find $cmd $matches]
  149.     }    
  150.     if [string length $match] {
  151.     # we completed or cancelled, so move on
  152.     completion::already error
  153.     if { $match == 1 } {
  154.         return 1
  155.     } else {            
  156.         if {![ring::type]} {
  157.         endOfLine
  158.         set p [getPos]
  159.         ring::+
  160.         insertText $match
  161.         goto $p
  162.         return [elec::findCmd $match TeXbodies ""]
  163.         }
  164.         if {![ring::TMarkAt "environment name" [pos::math [getPos] - [string length $match]]]} {
  165.         # we probably typed '\begin{name}' all in one go
  166.         set i "••"
  167.         if {[lookAt [pos::math [getPos] - 1]] != "\}"} {
  168.             append i "\}"
  169.         }
  170.         append i "\r\\end\{${match}\}\r••"
  171.         elec::Insertion $i
  172.         endOfLine
  173.         } else {
  174.         endOfLine
  175.         set p [getPos]
  176.         # delete the stop of the \end{•}
  177.         ring::+
  178.         ring::deleteStop
  179.         # we need to fill in the '\end{}'
  180.         insertText $match
  181.         goto $p
  182.         }
  183.         set ret [elec::findCmd $match TeXbodies ""]
  184.         # delete the stop of \begin{•}
  185.         # we do this afterwards, otherwise we lose the nesting of
  186.         # templates, which is bad.
  187.         ring::-
  188.         ring::deleteStopAndMove
  189.         return $ret
  190.     }
  191.     } else {
  192.     completion::already TeX::Completion::Env
  193.     return 1
  194.     }    
  195. }
  196.  
  197. ## 
  198.  # -------------------------------------------------------------------------
  199.  #     
  200.  # "TeX::Completion::Cmd" --
  201.  #    
  202.  #    Takes account of the backslash which commands in TeX use
  203.  # -------------------------------------------------------------------------
  204.  ##
  205. proc TeX::Completion::Cmd {dummy} {
  206.     set cmd [completion::lastWord pos]
  207.     if {[regexp {^\\([^\*]*)\*?$} $cmd "" cmd]} {
  208.     return [completion::cmd $cmd]
  209.     } else {
  210.     return 0
  211.     }
  212. }
  213.  
  214. ## 
  215.  # -------------------------------------------------------------------------
  216.  #     
  217.  #    "TeX::Completion::Electric"    --
  218.  #    
  219.  #     An    example    of calling the completion::electric procedure. 
  220.  #     In TeX mode, '{••}••' is a good default.
  221.  # -------------------------------------------------------------------------
  222.  ##
  223. proc TeX::Completion::Electric { {cmd ""} } {
  224.     if ![string length $cmd] { 
  225.     if [containsSpace $cmd] { return 0 }
  226.     set cmd [completion::lastWord]
  227.     }
  228.     if {[regexp {^\\([^\*]*)\*?$} $cmd "" cmd]} {
  229.     # nothing
  230.     } elseif {[regexp {\]\{?$} $cmd got]} {
  231.     # we might have an optional [...] after the command we really want.
  232.     # This should work but doesn't (Alpha bug)!
  233.     #{matchIt "]" [pos::math [getPos] - [expr 1 + [string length $got]]]}
  234.     if ![catch {search -s -f 0 -r 0 -m 0 "\[" [getPos]} where] {
  235.         set p [getPos]
  236.         goto [lindex $where 0]
  237.         set cmd [completion::lastWord]
  238.         goto $p
  239.         regexp {^\\([^\*]*)\*?$} $cmd "" cmd
  240.     }
  241.     }
  242.     return [completion::electric $cmd "\{••\}••"]
  243. }
  244.  
  245.     
  246. ## 
  247.  # -------------------------------------------------------------------------
  248.  #     
  249.  # "TeX::Completion::Reference"    --
  250.  #    
  251.  #    If we're in    any    kind of    reference, search for appropriate labels to
  252.  #    get    the    information    from and fill them in.    'TeXRefCompletion'
  253.  #    in "latexEngine.tcl" is    obsolete.
  254.  # -------------------------------------------------------------------------
  255.  ##
  256. proc TeX::Completion::Reference { {dummy ""} } {
  257.     global completion::in_progress_pos completion_got completion_looking
  258.     global _texrefprefixes
  259.     # cursor changed place?
  260.     set pos [getPos]
  261.     if {[pos::compare $pos == ${completion::in_progress_pos}]} {
  262.     completion::update Reference $completion_got $completion_looking
  263.     message "press <Cmd Tab> for another label"
  264.     return 1
  265.     }
  266.     
  267.     global TeXmodeVars
  268.     
  269.     set lastword [completion::lastTwoWords prevword]
  270.     set gotprefix ""
  271.     set prevword [string trim [string range $prevword 1 end] "\{"]
  272.     if {[set ref [lsearch -exact $TeXmodeVars(refCommands) $prevword]] != -1} {
  273.     set gotprefix $lastword
  274.     set lastword $prevword
  275.     } else {
  276.     # trim the backslash and opening brace:
  277.     set lastword [string trim [string range $lastword 1 end] "\{"]
  278.     # check if it's a \ref-like command:
  279.     set ref [lsearch -exact $TeXmodeVars(refCommands) $lastword]
  280.     }    
  281.     
  282.     if { $ref != -1 } {
  283.     # got a \ref-like command:
  284.     set completion_got "\\[lindex $TeXmodeVars(refCommands) $ref]\{${gotprefix}"
  285.     # make sure we have the brace:
  286.     if { $gotprefix == "" && [lookAt [pos::math $pos - 1]] != "\{" } {
  287.         insertText "\{"
  288.     }
  289.     set completion_looking "label\{${gotprefix}"
  290.     TeX::updateCompletion Reference $completion_got $completion_looking
  291.     completion::already Reference
  292.     return 1
  293.     } else {
  294.     return 0 
  295.     }
  296. }
  297.  
  298. ## 
  299.  # -------------------------------------------------------------------------
  300.  #     
  301.  # "TeX::Completion::Cite" --
  302.  #    
  303.  #    Checks for any \cite like command, and looks up    the    partial    argument
  304.  #    in the known bibliographies, completing    the    entry as appropriate.
  305.  # -------------------------------------------------------------------------
  306.  ##
  307. proc TeX::Completion::Cite { {dummy ""} } {
  308.     global completion::in_progress_pos completion_got completion_looking TeXmodeVars
  309.     # cursor changed place?
  310.     if {[pos::compare [getPos] == ${completion::in_progress_pos}]} {
  311.     set lastword [completion::lastWord]
  312.     set completion_got [completion::fromList $lastword completion_got]
  313.     } else {
  314.     global TeXmodeVars
  315.     set a [getText [lineStart [getPos]] [getPos]]
  316.     # got a \cite-like command:
  317.     if ![regexp "\\\\([join [string trim $TeXmodeVars(citeCommands)] |])\\\{(\[a-zA-Z0-9\]+,)*(\[a-zA-Z0-9\]+)$" $a d d d lastword] {
  318.         return 0
  319.     }
  320.     set completion_got [Bib::_FindAllEntries $lastword \
  321.       $TeXmodeVars(showTitlesWithTeXCiteCompletion)]
  322.     if {$completion_got == ""} {
  323.         if [catch {dialog::optionMenu \
  324.           "No matching citations found.  Perhaps you should\
  325.           rebuild your bib data-base, or create a new entry." \
  326.           [list "Rebuild database" "New entry" "New entry in new file"]} res] {
  327.         # user cancelled
  328.         return 0
  329.         }
  330.         switch $res {
  331.         "Rebuild database" {
  332.             if $TeXmodeVars(showTitlesWithTeXCiteCompletion) {
  333.             Bib::rebuildDatabase
  334.             } else {
  335.             Bib::rebuildIndex
  336.             }
  337.             # try again
  338.             return [TeX::Completion::Cite $dummy]
  339.         }
  340.         "New entry" {
  341.             Bib::_newEntry $lastword
  342.         }
  343.         "New entry in new file" {
  344.             Bib::_newEntry $lastword 1
  345.         }
  346.         }
  347.         return 0
  348.     }
  349.     }
  350.     if $TeXmodeVars(showTitlesWithTeXCiteCompletion) {
  351.     set query "Rebuild Bibliography Database"
  352.     set rebuild Bib::rebuildDatabase
  353.     } else {
  354.     set query "Rebuild Bibliography Index"
  355.     set rebuild Bib::rebuildIndex
  356.     }
  357.     set match [completion::Find $lastword $completion_got \
  358.       $TeXmodeVars(showTitlesWithTeXCiteCompletion) 1 $query $rebuild]
  359.     if {$match != ""} {
  360.     if {[lookAt [getPos]] != "\}"} { insertText "\}" }
  361.     }
  362.     # we never bother with calling ourselves again, since we forced the above
  363.     # 'completion::Find' call to complete.
  364.     completion::already error
  365.     return 1
  366. }
  367.  
  368. proc TeX::Completion::Word {dummy} {
  369.     # we only complete the word if it doesn't end in some command
  370.     if { [lookAt [pos::math [getPos] - 1]] != "\{" } {
  371.     return [completion::word $dummy]
  372.     }
  373. }
  374.  
  375. # ◊◊◊◊ helpers ◊◊◊◊ #
  376.  
  377. proc TeX::updateCompletion { proc {got ""} {looking ""} } {
  378.     if [completion::general $got $looking] {
  379.     if {[lookAt [getPos]] != "\}"} {
  380.         insertText "\}"
  381.     } 
  382.     completion::already $proc
  383.     message "press <Cmd Tab> for another label"
  384.     return 1
  385.     } else {
  386.     completion::already error
  387.     # if {[lookAt [expr [getPos] - 1]] != "\}"} {
  388.     #     elec::Insertion "\}••"        
  389.     # } 
  390.     error ""
  391.     return 0
  392.     }
  393. }    
  394.  
  395. # ◊◊◊◊ setup various arrays for electrics ◊◊◊◊ #
  396. uplevel \#0 [list source [file join ${HOME} Tcl Completions TeXcmds.tcl]]
  397.  
  398. hook::register TeX::labelDelimChanged TeX::adjustElectricLabels
  399. proc TeX::adjustElectricLabels {args} {
  400. uplevel \#0 {
  401. set _x $TeXmodeVars(standardTeXLabelDelimiter)
  402. set TeXelectrics(*section) "\{•section name•\}\n••"
  403. set TeXelectrics(frac) "\{•numerator•\}\{•denominator•\}••"
  404. set TeXelectrics(sum) "_\{•from•\}^\{•to•\}••"
  405. set TeXelectrics(emph) "◊1"
  406. set TeXelectrics(includegraphics) "◊\[TeX::IncludeFile\]"
  407. set TeXelectrics(begin) "\{•environment name•\}\n\\end\{••\}\n••"
  408. set TeXelectrics(Sec*) "◊kill0Section~\\ref\{sec${_x}•label•\}••"
  409. set TeXelectrics(Table) "~\\ref\{tab${_x}•label•\}••"
  410. set TeXelectrics(App*) "◊kill0Appendix~\\ref\{sec${_x}•label•\}••"
  411. set TeXelectrics(Eq.) "~\\eqref\{eq${_x}•label•\}••"
  412. set TeXelectrics(Fig*) "◊kill0Figure~\\ref\{fig${_x}•label•\}••"
  413. set TeXelectrics(Cha*) "◊kill0Chapter~\\ref\{chap${_x}•label•\}••"
  414. set TeXelectrics(mbox) "\{••\}"
  415. set TeXelectrics(fbox) "\{••\}"
  416. set TeXelectrics(mbox) "\{••\}"
  417. set TeXelectrics(parbox) "◊\[TeX::parbox\]"
  418. set TeXelectrics(makebox) "◊\[TeX::boxes\]"
  419. set TeXelectrics(framebox) "◊\[TeX::boxes\]"
  420. set TeXelectrics(raisebox) "◊\[TeX::raisebox\]"
  421. set TeXelectrics(newsavebox) "\{••\}"
  422. set TeXelectrics(usebox) "\{••\}"
  423. set TeXelectrics(sbox) "◊\[TeX::sbox\]"
  424. set TeXelectrics(savebox) "◊\[TeX::savebox\]"
  425. set TeXelectrics(rule) "◊\[TeX::rule\]"
  426. #set TeXelectrics(subfigure) "\[•caption•\]\{\\label\{fig${_x}••\}\}\%\r\\includegraphics\[•width=,height=•\]\{•eps file•\}\}"
  427. set TeXbodies(array) "◊\[TeX::BuildTabular array\]"
  428. set TeXbodies(equation) "\n\t•equation body•\n\t\\label\{eq${_x}•label•\}"
  429. set TeXbodies(description) "◊\[TeX::BuildList description\]"
  430. set TeXbodies(enumerate) "◊\[TeX::BuildList enumerate\]"
  431. set TeXbodies(itemize) "◊\[TeX::BuildList itemize\]"
  432. set TeXbodies(list) "◊\[TeX::BuildList list\]"
  433. set TeXbodies(trivlist) "◊\[TeX::BuildList trivlist\]"
  434. set TeXbodies(figure) "◊\[TeX::Figure\]"
  435. set TeXbodies(table) "\n\t••\n\t\\caption•\[short title for t.o.t.\]•\{•caption•\}\n\t\\protect[TeX::label tab]"
  436.  
  437. set TeXbodies(tabular) "◊\[TeX::BuildTabular tabular\]"
  438. set TeXbodies(tabular*) "◊\[TeX::BuildTabular tabular*\]"
  439. set TeXbodies(gather) "\n\t•• \n\t\\label\{eq${_x}••\} \\\\\n\t•• \n\t\\label\{eq${_x}••\}"
  440. set TeXbodies(split) "\n\t•• &•• \\\\\n\t•• &•• \\\\"
  441. set TeXbodies(cases) "\n\t•• & •• \\\\\n\t•• & ••"
  442.  
  443. set TeXbodies(equationarray) "◊\[TeX::equationarray\]"
  444. set TeXbodies(minipage) "◊\[TeX::minipage\]"
  445. set TeXbodies(matrix) "◊\[TeX::matrix\]"
  446. set TeXbodies(pmatrix) "◊\[TeX::matrix\]"
  447. set TeXbodies(bmatrix) "◊\[TeX::matrix\]"
  448. set TeXbodies(vmatrix) "◊\[TeX::matrix\]"
  449. set TeXbodies(Vmatrix) "◊\[TeX::matrix\]"
  450. set TeXbodies(align) "◊\[TeX::align\]"
  451. set TeXbodies(alignat) "◊\[TeX::alignat\]"
  452.  
  453. set TeXbodies(align) "\n\t•equation 1 l.h.s.• &•• \n\t\\label\{eq${_x}••\} \\\\\n\t•equation 2 l.h.s.• &•• \n\t\\label\{eq${_x}••\}"
  454.  
  455. set TeXEnvItems(enumerate) "\n\\item ••"
  456. set TeXEnvItems(itemize) "\n\\item ••"
  457. set TeXEnvItems(description) "\n\\item\[•name•\] •description•"
  458. set TeXEnvItems(align) "\\\\\n•next equation l.h.s.• &•• \n\\label\{eq${_x}••\} "
  459. set TeXEnvItems(gather) "\\\\\n•• \n\\label\{eq${_x}••\} "
  460. set TeXEnvItems(split) "•• &•• \\\\"
  461. set TeXEnvItems(cases) "•• &•• \\\\"
  462. set _texrefprefixes [list fig${_x} eq${_x} sec${_x} chap${_x} tab${_x} ]
  463. unset _x
  464. }
  465.  
  466. }
  467.  
  468. # call it now
  469. TeX::adjustElectricLabels
  470.  
  471.  
  472. # ◊◊◊◊ environment assistors ◊◊◊◊ #
  473.  
  474. ## 
  475.  # -------------------------------------------------------------------------
  476.  #     
  477.  # "TeXAddItem"    --
  478.  #    
  479.  #    Scan the local environment and insert a    new    item into that environment,
  480.  #    of the appropriate type.
  481.  #    
  482.  #    Currently not too sophisticated.
  483.  # -------------------------------------------------------------------------
  484.  ##
  485. proc TeXAddItem {} {
  486.     set env [lindex [split [eval getText [searchEnvironment]] "{}"] 1]
  487.     global TeXEnvItems
  488.     if ![catch {set item $TeXEnvItems($env)}] {
  489.     elec::Insertion $item
  490.     }
  491. }
  492.  
  493. # ◊◊◊◊ Template embeddable proc's ◊◊◊◊ #
  494.  
  495. proc TeX::IncludeFile {} {
  496.     # could try to ensure this file's on the search path?
  497.     if ![regexp {\{, } [lookAt [pos::math [getPos] - 1]]] {
  498.     append res "\{"
  499.     }
  500.     append res [file tail [getfile "Name of file to include:"]]
  501.     return $res
  502. }
  503.     
  504.  
  505.  
  506. # ◊◊◊◊ Expansions ◊◊◊◊ #
  507. namespace eval TeX::Expansion {}
  508.  
  509. # proc by Tom Fetherston
  510. proc TeX::Expansion::ExCmd { {cmd ""} {dictExt "acronyms"}} {
  511.     if ![string length $cmd] { 
  512.     set cmd [completion::lastWord]
  513.     # if there's any whitespace in the command then it's no good to us
  514.     if [containsSpace $cmd] { return 0 }
  515.     }
  516.     
  517.     set m [modeALike]
  518.     set hint [string trim [join [split $cmd \\ ]]]
  519.     
  520.     if { [set matches [elec::acronymListExpansions $hint ${m}${dictExt}]] == 0 } {
  521.     return 0
  522.     } else {
  523.     set result [elec::expandThis $cmd $matches]
  524.     set match [lindex  $result 0]
  525.     catch {set keystroke [lindex $result 1]}
  526.     if [string length $match] {
  527.         # we completed or cancelled, so move on
  528.         # WHY ISN'T THIS 'alreadyExpanding' ???????????? vmd
  529.         completion::already error
  530.         if { $match == 1 } {
  531.         return 1
  532.         } else {
  533.         set curPos [getPos]
  534.         set retVal [completion [modeALike] Electric "${match}"]
  535.         if {([pos::compare [getPos] == $curPos]) && [info exists keystroke]} {
  536.             insertText $keystroke
  537.         } 
  538.         return $retVal
  539.         }
  540.     } else {
  541.         elec::alreadyExpanding Cmd
  542.         return 1
  543.     }
  544.     }
  545.     
  546. }
  547.  
  548.